package com.ucomm.talent.activity.detail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.ViewStub;
import android.widget.TextView;

import com.ucomm.talent.AppConfig;
import com.ucomm.talent.AppConstants;
import com.ucomm.talent.AppException;
import com.ucomm.talent.R;
import com.ucomm.talent.activity.IHeaderBarClickListener;
import com.ucomm.talent.common.DebugUtil;
import com.ucomm.talent.manager.DetailSearchManager;
import com.ucomm.talent.model.TalentsDetailsInfo;
import com.ucomm.talent.model.TalentsInfo;
import com.ucomm.talent.widget.CustomProgressDialog;
import com.ucomm.talent.widget.MainHeaderBar;

public class TalentsDetailsActivity extends Activity implements IHeaderBarClickListener{
	
	private MainHeaderBar mainHeaderBar;
	private int id = 0;
	private CustomProgressDialog customProgressDialog;
	private ViewStub talents_details_vs1;
	private ViewStub talents_details_vs2;
	private TextView name;
	private TextView salary_tv;
	private TextView job_son_tv;
	private TextView address_tv;
	private TextView job_post_tv;
	private TextView time_tv;
	private TextView properties_tv;
	private TextView work_experience;
	private TalentsInfo info;
	
	Handler mHandler = new Handler(){
        @Override
    public void handleMessage(Message msg) {
        int what = msg.what;
        DebugUtil.Log(TalentsDetailsActivity.this,"---------- " + customProgressDialog.toString());
        switch (what){
            case AppConstants.MsgStatus.MSG_ERROR:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                ((AppException)msg.obj).makeToast(TalentsDetailsActivity.this);
                break;
            case AppConstants.MsgStatus.MSG_SUCCUSS:
                if (customProgressDialog != null && customProgressDialog.isShowing())
                    customProgressDialog.dismiss();
                //获取数据
                TalentsDetailsInfo details = (TalentsDetailsInfo) msg.obj;
                name.setText(details.getName());
                String job_son = null;//行业
                String address = null;
                String job_post = null;//职位
                String time = null;
                String properties = null;
                if(AppConfig.cityMap.size()!=0 && AppConfig.userMap.size()!=0 && AppConfig.jobMap.size()!=0){
                	address = AppConfig.cityMap.get(details.getProvinceId())+AppConfig.cityMap.get(details.getCityId());
                	time = AppConfig.userMap.get(details.getReport());
                	properties = AppConfig.userMap.get(details.getType());
                	job_son = AppConfig.jobMap.get(details.getJob1_son());
                	job_post = AppConfig.jobMap.get(details.getJob_post());
                }
                job_son_tv.setText(job_son);
                address_tv.setText(address);
                job_post_tv.setText(job_post);
                time_tv.setText(time);
                properties_tv.setText(properties);
                
                break;
            case AppConstants.MsgStatus.MSG_LOADING:
                if (customProgressDialog != null && !customProgressDialog.isShowing())
                    customProgressDialog.show();
                break;
            default:
                break;
        }
        super.handleMessage(msg);
    }
	};
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.talents_details_layout);
		Intent i = getIntent();
		info = (TalentsInfo) i.getSerializableExtra("info");
		id = info.getResumeId();
		
		initView();
		DetailSearchManager detailSearchManager = new DetailSearchManager(this, mHandler);
        final String url = AppConstants.TALENTS_DETAILS+id;
        detailSearchManager.searchDetailDataFromNetwork(url);
	}
	private void initView(){
		mainHeaderBar = (MainHeaderBar) findViewById(R.id.main_header_bar);
		mainHeaderBar.setBarClickListener(this);
		name = (TextView) findViewById(R.id.name);
		customProgressDialog = new CustomProgressDialog(this);
		talents_details_vs1 = (ViewStub) findViewById(R.id.talents_details_vs1);
		talents_details_vs2 = (ViewStub) findViewById(R.id.talents_details_vs2);
		talents_details_vs1.inflate();
		talents_details_vs2.inflate();
		salary_tv = (TextView)findViewById(R.id.salary_tv);
		String salary = null;
		if(AppConfig.userMap.size()!=0){
			salary = AppConfig.userMap.get(info.getSalary()+"");
		}
		salary_tv.setText(salary);
		job_son_tv = (TextView)findViewById(R.id.job_son_tv);
		address_tv = (TextView)findViewById(R.id.address_tv);
		job_post_tv = (TextView)findViewById(R.id.job_post_tv);
		time_tv = (TextView)findViewById(R.id.time_tv);
		properties_tv = (TextView)findViewById(R.id.properties_tv);
		work_experience = (TextView)findViewById(R.id.work_experience);
	}
	@Override
	public void onBackButtOnClick(View view) {
		// TODO Auto-generated method stub
		finish();
	}

	@Override
	public void onExitButtonOnClick(View view) {
		// TODO Auto-generated method stub
		
	}

}
